import overDue from './overDue'
export const login = function (that) {
    wx.request({
        url: 'https://www.openrzcl.com/prod-out-api/appUser/login',
        method: 'GET',
        data: that.normal,
        header: {
            'content-type': 'application/json'
        },
        success(res) {
            //globalData.phone = res.data.luser.phone;
            if (res.data.code == 200) {
                // var key = overDue(new Date())
                // wx.setStorageSync('key', key);
                wx.setStorageSync('key', 1);
                // wx.setStorageSync('token', { token: res.data.data, usercode: that.normal.usercode });
                wx.setStorageSync('token', res.data.data);
                wx.setStorageSync('usercode', that.normal.usercode);
                setTimeout(() => {
                    wx.showToast({
                        title: `登录成功！`,
                        icon: 'none'
                    });
                }, 50);
                setTimeout(() => {
                    wx.switchTab({
                        url: '/pages/work/main'
                    })
                    that.normal.usercode = '';
                    that.normal.password = '';
                }, 1000);
            } else {
                wx.showToast({
                    title: `用户名或密码错误，请重新登录！`,
                    icon: 'none'
                });
                that.normal.usercode = '';
                that.normal.password = '';
            }
        },
        fail(err) {
            console.log('login err:', err);
        }
    });
}